package com.googlecode.gwtbb.client.only.widget.basic;

import com.google.gwt.user.client.ui.SuggestionEvent;
import com.google.gwt.user.client.ui.SuggestionHandler;
import com.google.gwt.user.client.ui.TextBoxBase;
import com.googlecode.gwtbb.client.shared.util.StringUtils;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Aug 7, 2008
 */
public class SelectSuggestionHandler implements SuggestionHandler {
	TextBoxBase box;

	public SelectSuggestionHandler(TextBoxBase box) {
		this.box = box;
	}

	public void onSuggestionSelected(SuggestionEvent event) {
		selectAllBoxText();
	}

	public void selectAllBoxText() {
		box.setFocus(true);
		String text = box.getText();
		if (StringUtils.isNotEmpty(text)) {
			box.setCursorPos(text.length());
			box.setSelectionRange(0, text.length());
		}
	}
}
